<%@page import="com.core.util.DspUtil"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="../common/header.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>DSP</title>
<%
	String yearMonth = DspUtil.getCurrentYearMonth();//当前年月
	String currMonth = yearMonth.substring(4); //当前月份
	String currDate = DspUtil.getCurrentDate();
	String nextDate = DspUtil.getNextYearDate().toString();
%>
<%@include file="../common/link.jsp"%>
<link href="css/uploadify.css" rel="stylesheet" type="text/css" />
<script src="js/swfobject.js"></script>
<script src="js/jquery.uploadify.v2.1.4.min.js"></script>
<script src="js/idcard.js"></script>
<script src="javascript?type=selectTags"></script>
<script src="javascript?type=Com"></script>
<script>
	var errorMsg = new Array();
	function check(){
		for (var i = 0 ; i < errorMsg.length; i++){
			if(errorMsg[i] != ''){
				warning(errorMsg[i]);
				return false;
			}
		}
		return true;
	}
	var config = {
		url : "employees"
	}
	var colModel = [{
		title : ' 公司',
		field : 'company',
		width : 90,
		algin : 'left',
		formatter : function(cell, row , index) {
			var val = '';
			for ( var i = 0; i < Com.length; i++) {
				if (cell == Com[i].id) {
					val = Com[i].value;
					break;
				}
			}
			return val;
		}
	}, {
		title : '姓名',
		field : 'empname',
		width : 60,
		//sortable : true,
		align : 'left',
		formatter : function(cell, row , index) {
			return "<a href='###' onclick='javascript:DSP.update("+row.id+");' >" + cell + "</a>";
		},
		link : true
	//超连接 

	}, {
		title : '性别',
		field : 'sex',
		width : 30,
		//sortable : true,
		align : 'left',
		formatter : function(cell, row , index) {
			return selectTags["sex_" + cell];
		}
	}, {
		title : '<font color="blue">社保状态</font>',
		field : 'isInsure',
		width : 40,
		//sortable : true,
		align : 'center',
		formatter : function(cell, row , index) {
			var color = '';
			if(cell == '0'){
				color='blue';
			} else if (cell == 2){
				color = 'red';
			} 
			return '<font color="'+color+'">'+selectTags["insure_"+cell]+'</font>';
		}
	},{
		title : '社保基数',
		field : 'insureBase',
		width : 50,
		align : 'center',
		formatter:function(cell , row ,index){
			if(row.isInsure != '0') {//已加保
				return cell;
			} 
			return ''; //未加保，就先不显示基数了，虽然默认存将公司的基数存入
		}
	}, {
		title : '<font color="blue">公积金状态</font>',
		field : 'isProvident',
		width : 40,
		//sortable : true,
		align : 'center',
		formatter : function(cell, row , index) {
			var color = '';
			if(cell == '0'){
				color='blue';
			} else if (cell == 2){
				color = 'red';
			} 
			return '<font color="'+color+'">'+selectTags["insure_"+cell]+'</font>';
		}
	}, {
		title : '公积金基数',
		field : 'providentBase',
		width : 50,
		align : 'center',
		formatter:function(cell , row ,index){
			if(row.isProvident != '0') {//已加保
				return cell;
			} 
			return ''; //未加保，就先不显示基数了，虽然默认存将公司的基数存入
		}
	},{
		title : '合同开始日期',
		field : 'bargainBegin',
		width : 80,
		align : 'center'
	}, {
		title : '合同结束日期',
		field : 'bargainEnd',
		width : 80,
		align : 'center'
	}, {
		title : '户口性质',
		field : 'hukou',
		width : 60,
		align : 'center',
		formatter : function(cell, row , index) {
			return selectTags["hukou_" + cell];
		}
	}];
	var btnModel = ['-',
	{
		id : 'uploader',
		text : '上传员工资料',
		iconCls : 'icon-add',
		handler : function() {
			$("#upload_div").dialog('open');
		}
	}];
</script>
</head>
<body>
<form id="qForm">
		<table width="60%" cellspacing="3" cellpadding="3"
			bordercolor="#DEDEDC" border="0" id="q-form" >
			<tr>
				<th width="15%" class="td_left" valign="middle">公司:</th>
				<td width="20%"><select id="q_company" name="q_company"></select>
				</td>
				<th width="15%" class="td_left" valign="middle">姓名:</th>
				<td width="20%"><input type="text" name="q_empname" id="q_empname" />
				</td>
			</tr>
			<tr>
				<th width="15%" class="td_left" valign="middle">代理方式:</th>
				<td><input type="text" name="q_cMethod" id="q_cMethod" />
				</td>
				<th class="td_left" valign="middle">户口性质:</th>
				<td><dsp:selectTag htmlId="q_hukou" tagId="hukou" isAll="true"/>
				</td>
			</tr>
			<tr>
				<th width="10%" class="td_left" valign="middle">社保状态:</th>
				<td><dsp:selectTag htmlId="q_isInsure" tagId="insure" isAll="true"/>
				</td>
				<th class="td_left" valign="middle">公积金状态:</th>
				<td><dsp:selectTag htmlId="q_isProvident" tagId="insure" isAll="true"/>
				</td>
			</tr>
		</table>
		</form>
	<div id="dialog_div" class="easyui-window" title="员工信息"
		collapsible="false" minimizable="false" maximizable="false"
		icon="icon-save"
		style="left: 100px; top: 10px; padding: 5px; background: #fafafa;">
		<div class="easyui-layout" fit="true">
			<div region="center" border="false"
				style="padding: 10px; background: #fff; border: 1px solid #ccc;">
				<form action="" id="form1" name="form1">
					<input type="hidden" name="id" id="id" value="" />
					<input type="hidden" name="isInsure" id="isInsure" value=""/>
					<input type="hidden" name="isProvident" id="isProvident" value="" />
					<table width="100%" cellspacing="3" cellpadding="3" bordercolor="#DEDEDC" border="0" id="id-form">
						<tr>
							<th class="td_right" valign="middle"><span
								style="color: #FF0000">*</span>姓名:</th>
							<td><input type="text" name="empname" id="empname" size="25"
								jval="{valid:function(val){ if (val.length == 0){  return '不能为空'; } else {  return ''; }}}" />
							</td>
							<th class="td_right" valign="middle"><span
								style="color: #FF0000">*</span>公司</th>
							<td><select id="company" name="company"
								jval="{valid:function(val){ if (val.length == 0){  return '不能为空'; } else {  return '';}}}">
							</select>
							<script>
							var options = "<option value=''>请选择公司</option>";
							$.each(Com, function(i, d) {
								if(d.id != '')
									options += "<option value="+d.id+">" + d.value + "</option>";
							});
							$('#company').empty().append(options);
							$("#q_company").empty().append(options);
							</script>
							</td>
						</tr>
						<tr>
							<th class="td_right" valign="middle"><span
								style="color: #FF0000">*</span>身份证:</th>
							<td><input type="text" name="empidn" id="empidn" size="25"
								jval="{valid:function(val){ return checkIempidn(val); }}"
								maxlength="18" /></td>
							<th class="td_right" valign="middle"><span
								style="color: #FF0000">*</span>性别:</th>
							<td><dsp:radioTag htmlId="sex" htmlValue="" tagId="sex"
									oAction="" />
							</td>
						</tr>
						<tr>
							<th class="td_right" valign="middle">职位:</th>
							<td colspan="3"><input type="text" name="job" id="job" />
							</td>
						</tr>
						<tr>
							<th class="td_right" valign="middle"><span style="color:#FF0000;">*</span>代理方式:</th>
							<td><input type="text" name="cMethod" id="cMethod" jval="{valid:function(val){if (val.length == 0){  return '不能为空'; } else {  return '';}}}" /></td>
						</tr>
						<tr>
							<th class="td_right" valign="middle"><span
								style="color: #FF0000">*</span>合同开始日期:</th>
							<td><input id="bargainBegin" name="bargainBegin" value="" type="text"/>
							</td>
							<th class="td_right" valign="middle"><span
								style="color: #FF0000">*</span>合同结束日期:</th>
							<td><input type="text" id="bargainEnd" size="25"
								name="bargainEnd" maxlength="10"  
								jval="{valid:function(val){if (val.length == 0){  return '不能为空'; } else {  return '';}}}" />
							</td>
						</tr>
						<tr style="display:none;">
							<th class="td_right" valign="middle">参保月份:</th>
							<td colspan="3"><dsp:radioTag htmlId="empMonth"
									htmlValue="<%=currMonth%>" tagId="month" />
							</td>
						</tr>
						<tr id="showInsure" style="display:none;">
							<th class="td_right" valign="middle">社保基数:</th>
							<td colspan="3"><input type="text" id="insureBase" name="insureBase"
								size="25" />
							</td>
						</tr>
						<tr id="showProvident" style="display:none;">
						<th class="td_right" valign="middle">公积金基数:</th>
							<td colspan="3"><input type="text" id="providentBase"
								name="providentBase" size="25" />
							</td>
						</tr>
						<tr>
							<th class="td_right" valign="middle">户口性质:</th>
							<td colspan="3"><dsp:radioTag htmlId="hukou" htmlValue=""
									tagId="hukou" />
							</td>
						</tr>
						<tr>
							<th class="td_right" valign="middle">联系电话:</th>
							<td><input type="text" name="telphone" id="telphone"
								size="25" value="" />
							</td>
							<th class="td_right" valign="middle">社保卡号:</th>
							<td><input type="text" name="insureCard" id="insureCard"
								size="25" value="" />
							</td>
						</tr>
						<tr>
							<th class="td_right" valign="middle">失业登记号:</th>
							<td><input type="text" name="loseCard" id="loseCard"
								size="25" value="" />
							</td>
							<th class="td_right" valign="middle">民族:</th>
							<td><input type="text" name="national" id="national"
								size="25" value="" />
							</td>
						</tr>
						<tr>
							<th class="td_right" valign="middle">何时参加工作:</th>
							<td><input type="text" name="jobBegin" id="jobBegin"
								size="25" value="" />
							</td>
						</tr>
						<tr>
							<th class="td_right" valign="middle">最高学历:</th>
							<td colspan="3"><dsp:radioTag htmlId="education"
									htmlValue="" tagId="edu" /></td>
						</tr>
					</table>
				</form>
			</div>
			<div region="south" border="false"
				style="text-align: right; height: 30px; line-height: 30px;">
				<a id="btnEp" class="easyui-linkbutton" icon="icon-ok"
					href="javascript:DSP.send();"> 确定</a> <a id="btnCancel"
					class="easyui-linkbutton" icon="icon-cancel"
					href="javascript:DSP.close();">取消</a>
			</div>
		</div>
	</div>
	<table id="xDataGrid"></table>
	<script type="text/javascript">
	$(function() {
		$("#bargainBegin").datebox();
		$("#bargainEnd").datebox();
		//$("#cc").calendar({width:600,height:600,current:new Date()})
		DSP.open(false,500 , 700 ,"");
		//DSP.open("#upload_div",230,300,"");
		DSP.grid(colModel, btnModel, null , "员工信息");
		
		//监听查询输入框事件
		$("#q-form input").keyup(function(event){
			var e = event || window.event; //浏览器兼容
			if(e.keyCode == 13){ 
				 DSP.grid.query();
			}
		});
		
		//监听查询输入框事件
		$("#q-form select").change(function(){
			DSP.grid.query();
		});
		
		$("#empidn").change(function(){
			var idCard = $("#empidn").val();
			var error = checkIempidn(idCard);
			if (error != ''){
				warning(error);
			}
		});
		
		$("#upload_div").dialog({
			modal:true,
			open:false,
			buttons:[{
				text:'开始上传', iconCls:'icon-ok',handler:function(){
					jQuery("#uploadify").uploadifyUpload();
				}
			},{
				text:'取消上传', iconCls:'icon-cancel',handler:function(){
					jQuery("#uploadify").uploadifyClearQueue();
				}
			}]
		});
		$("#upload_div").dialog('close');
		
		var scriptData = new Array();
		scriptData['Code'] = 'EMP';
		 $("#uploadify").uploadify({  
             'uploader'       : 'js/uploadify.swf',  
             'script'         : 'uploader',  
             'cancelImg'      : 'images/cancel.png',  
             'folder'         : 'uploads',  
             'queueID'        : 'fileQueue',  
             'auto'           : false,  
             'method'		  : 'GET',
             'multi'          : false,  
             'fileDesc': '只支持xls格式的文件',
             'fileExt': '*.xls',
             'sizeLimit':10240000,
             'simUploadLimit':1,
             'buttonText'     : 'Brower',
             'scriptData' : scriptData,
             'onComplete' : function(e, queueId, fileObj,response ,data) {
				var json = eval("("+ response + ")");
				if (json.success) {
					infos("上传成功");
					$("#upload_div").dialog("close");
					$("#xDataGrid").datagrid('clearSelections');
					DSP.grid.query(); // 重新加载数据
				} else {
					infos("上传失败");
				}
             } ,
             'onError' : function(e , queueId , fileObj,errorObj) {
            	   //errorObj .type 和 info
            	   warning(errorObj.info);
             }
         });  
	
		getCompany();
		function getCompany() {
			$.ajax({
				type : 'POST',
				contentType : 'application/json',
				ansync : true,
				dataType : 'json',
				url : 'companys_sss',
				success : function(data) {
					var options = "<option value=''>请选择公司</option>";
					$.each(data, function(i, d) {
						options += "<option value="+d.id+">" + d.cname + "</option>";
					});
					$('#company').empty().append(options);
				}
			});
		}
	});
	function update(data) {
		$("#id").attr("value",data.id);
		$("#isInsure").attr("value",data.isInsure);
		$("#isProvident").attr("value",data.isProvident);
		$("#cMethod").attr("value",data.cMethod);
		$("#empname").attr("value", data.empname);
		$("#company").attr("value", data.company);
		$("#empidn").attr("value", data.empidn);
		//$("input[name=sex][value="+data.sex+"]").attr("checked",true);//value=0的radio被选中
		DSP.setRadio('sex',data.sex);
		//$("#sex").attr("value", data.sex);
		//$("input[name=job][value="+data.job+"]").attr("checked",true);//value=0的radio被选中
		$('#job').attr("value", data.job);
		//$("#job").attr("value",data.job);
		$("#barginBegin").datebox("setValue",data.bargainBegin);
		$("#bargainBegin").attr("value", data.bargainBegin);
		$("#bargainEnd").attr("value", data.bargainEnd);
		$("#empMonth").attr("value", data.empMonth);
		$("#insureBase").attr("value", data.insureBase);
		$("#providentBase").attr("value", data.providentBase);
		//$("#hukou").attr("value", data.hukou);
		DSP.setRadio('hukou',data.hukou);
		$("#telphone").attr("value", data.telphone);
		$("#insureCard").attr("value", data.insureCard);
		$("#loseCard").attr("value", data.loseCard);
		$("#national").attr("value", data.national);
		$("#jobBegin").attr("value", data.jobBegin);
		//$("#education").attr("value", data.education);
		DSP.setRadio('education',data.education);
		show();
	}
	
	function checkIempidn(val){
		if (val == ''){
			return '不能为空';
		}
		var error = checkIdcard(val);
		if (error != ''){
			error[0] = error;
			return error;
			//alert(error);
		} else {
			delete error[0];
			getSex(val);
		}
		return '';
	}
	function CallBackFunc(){
		document.getElementById("bargainBegin").value = '<%=currDate%>';
		document.getElementById("bargainEnd").value = '<%=nextDate%>';
	}
	
	function show(){
		if($_("isInsure").value != "" && parseInt($_("isInsure").value) > 0){
			$_("showInsure").style.display = '';
		} else {
			$_("showInsure").style.display = "none";
		}
		if($_("isProvident").value != "" && parseInt($_("isProvident").value) > 0){
			$_("showProvident").style.display = '';
		} else {
			$_("showProvident").style.display = "none";
		}
	}
	</script>
<div id="upload_div" icon="icon-save" style="padding:5px;width:400px;height:200px;" title="上传员工资料">
	 <div id="fileQueue"></div>
	 <input type="file" name="uploadify" id="uploadify" />
</div>
</body>
</html>
